package com.cisetech.mapper.xml;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;

public class XmlToJava {
	public Object xmlToJava(Object object,String xml){
			try {
				JAXBContext context;
				context = JAXBContext.newInstance(object.getClass());//jdk1.5以后就自带这个包了要是没有的话可以导入
				Unmarshaller unmarshaller = context.createUnmarshaller();
				//将字符串转成InputStream流
				InputStream in=new ByteArrayInputStream(xml.getBytes()); 
				InputStreamReader is=new InputStreamReader(in,"gbk");
				//封装到自己的实体类中
				Object resp = (Object) unmarshaller.unmarshal(is);
				return resp;
			} catch (Exception e) {
				e.printStackTrace();
			}
			return null;
	}
}
